package com.ruoyi.find.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.find.domain.ArticleCategory;
import com.ruoyi.find.service.IArticleCategoryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 文章分类Controller
 * 
 * @author gjq
 * @date 2025-09-16
 */
@RestController
@RequestMapping("/category")
public class ArticleCategoryController extends BaseController
{
    @Autowired
    private IArticleCategoryService articleCategoryService;

    /**
     * 查询文章分类列表
     */
    @RequiresPermissions("find:category:list")
    @GetMapping("/list")
    public TableDataInfo list(ArticleCategory articleCategory)
    {
        startPage();
        List<ArticleCategory> list = articleCategoryService.selectArticleCategoryList(articleCategory);
        return getDataTable(list);
    }

    /**
     * 导出文章分类列表
     */
    @RequiresPermissions("find:category:export")
    @Log(title = "文章分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleCategory articleCategory)
    {
        List<ArticleCategory> list = articleCategoryService.selectArticleCategoryList(articleCategory);
        ExcelUtil<ArticleCategory> util = new ExcelUtil<ArticleCategory>(ArticleCategory.class);
        util.exportExcel(response, list, "文章分类数据");
    }

    /**
     * 获取文章分类详细信息
     */
    @RequiresPermissions("find:category:query")
    @GetMapping(value = "/{categoryName}")
    public AjaxResult getInfo(@PathVariable("categoryName") String categoryName)
    {
        return success(articleCategoryService.selectArticleCategoryByCategoryName(categoryName));
    }

    /**
     * 新增文章分类
     */
    @RequiresPermissions("find:category:add")
    @Log(title = "文章分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleCategory articleCategory)
    {
        return toAjax(articleCategoryService.insertArticleCategory(articleCategory));
    }

    /**
     * 修改文章分类
     */
    @RequiresPermissions("find:category:edit")
    @Log(title = "文章分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleCategory articleCategory)
    {
        return toAjax(articleCategoryService.updateArticleCategory(articleCategory));
    }

    /**
     * 删除文章分类
     */
    @RequiresPermissions("find:category:remove")
    @Log(title = "文章分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryNames}")
    public AjaxResult remove(@PathVariable String[] categoryNames)
    {
        return toAjax(articleCategoryService.deleteArticleCategoryByCategoryNames(categoryNames));
    }
}
